package com.kaisheng.service;

import java.util.List;

import com.kaisheng.dao.IdeaCommentDao;
import com.kaisheng.dao.IdeaDao;
import com.kaisheng.dao.IdeaMainDao;
import com.kaisheng.dao.UserDao;
import com.kaisheng.entity.Idea;
import com.kaisheng.entity.User;

import com.kaisheng.util.DateUtil;
import com.kaisheng.util.PKUtil;
import com.kaisheng.util.Page;


public class IdeaService {
	IdeaMainDao imdao = new IdeaMainDao();
	IdeaDao ideadao =  new IdeaDao();
	IdeaCommentDao commentdao = new IdeaCommentDao();
	UserDao udao = new UserDao();
	public List<Idea> findAllIdeasByProjectId(String project_id) {
		
		return imdao.findAllByProjectId(project_id);
	}
	public void saveNewIdea(String title, String content, String user_id,String project_id) {
	
		Idea i= new Idea();
		i.setId(PKUtil.getId());
		i.setTitle(title);
		i.setContent(content);
		i.setCreatetime(DateUtil.getNowDateTime());
		i.setUser_id(user_id);
		i.setProject_id(project_id);
		
		ideadao.saveIdea(i);
		
	}
	public Idea findSpecificIdea(String ideaid) {
		
		return ideadao.findIdeaById(ideaid);
	}
	public void update(String id, String title, String content,String createtime) {
	
	
		ideadao.updateIdea(id,title,content,createtime);
	}
	
	public void deleteIdea(String id) {
		ideadao.deleteIdeaById(id);
		
	}
	public User findById(String userid) {
		
		return udao. findByUserId(userid);
	}

	/**
	 * 
	 * @param pageNum
	 * @return
	 */

	
	public Page<Idea> findAll(String project_id,Long count,int pageNum) {
		Page<Idea> page = new Page<Idea>(2,count,pageNum);
	
		return imdao.findAll(project_id,page);
		
	}
	

}
